local jijie = fk.CreateSkill{
  name = "iberia__jijie",
}

Fk:loadTranslationTable{
  [jijie.name] = " 机捷",
  [":"..jijie.name] = "每回合每个技能限一次，当你使用牌时，若你的一个技能中包含此牌名的牌，你可以令一名角色摸一张牌。",

  ["#"..jijie.name] = "机捷：可以令一名角色摸一张牌",
}

local I = require "packages/iberia/utility"

local jijieSkill = function (player, skill, card_name)
  return string.find(Fk:translate(":"..skill.name), "【"..Fk:translate(card_name).."】")
  and not table.contains(player:getTableMark("iberia__jijie-turn"), skill.name)
end

jijie:addEffect(fk.CardUsing, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(jijie.name) and player == target and data.card
    and table.find(player.player_skills, function (s)
      print(s.name)
      return jijieSkill(player, s, data.card.name)
    end)
  end,
  on_cost = function (self, event, target, player, data)
    local skills = table.filter(player.player_skills, function (s)
      return jijieSkill(player, s, data.card.name)
    end)
    local tos, op = I.askToChoosePlayersAndChoice(player, {
      targets = player.room.alive_players,
      min_num = 1,
      max_num = 1,
      choices = table.map(skills, function (s) return s.name end),
      skill_name = jijie.name,
      prompt = "#"..jijie.name,
    })
    if #tos == 0 then return end

    event:setCostData(self, { tos = tos, op = op })
    return true
  end,
  on_use = function (self, event, target, player, data)
    local tos, op = event:getCostData(self).tos, event:getCostData(self).op
    player.room:addTableMark(player, "iberia__jijie-turn", op)
    player.room:drawCards(tos[1], 1, jijie.name)
  end
})

return jijie
